﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace EmployeeCheckIn
{
    public partial class AdminDetail : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              int i = Convert.ToInt32(Session["Detailadmin_id"].ToString());
              Showlb();
              dataGridDetail(i);
            }
            
        }
        private void Showlb()
        {
            lbTitle.Visible = true;
            lbStatus.Visible = true;
            lbPhone.Visible = true;
            lbName.Visible = true;
            lbLastName.Visible = true;
            lbDateRegis.Visible = true;
            //lbUserName.Visible = true;
        }
        private void dataGridDetail(int i)
        {
            DataTable dt = GetData(i);

            if (dt != null && dt.Rows.Count > 0)
            {

                //lbUserName.Text = dt.Rows[0]["user_name"].ToString();
                lbUserName0.Text = dt.Rows[0]["user_name"].ToString();
                string title = dt.Rows[0]["admin_title"].ToString();
                lbName.Text = dt.Rows[0]["admin_name"].ToString();
                lbLastName.Text = dt.Rows[0]["admin_lastname"].ToString();
                lbPhone.Text = dt.Rows[0]["admin_phone"].ToString();
                lbDateRegis.Text = Convert.ToDateTime(dt.Rows[0]["admin_date_regis"].ToString()).ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("th-TH"));
                string status = dt.Rows[0]["admin_status_id"].ToString();
                if (title == "1")
                {
                    lbTitle.Text = "นาย"; 
                }
                if (title == "2")
                {
                    lbTitle.Text = "นาง";
                }
                if (title == "3")
                {
                    lbTitle.Text = "นางสาว";
                }
                if (status == "1")
                {
                    lbStatus.Text = "SUPER ADMIN";
                }
                if (status == "2")
                {
                    lbStatus.Text = "ADMIN";
                }

            }
        }
        private DataTable GetData(int i)
        {
            string sqltext = @"select user_name
                                     ,admin_title
                                     
                                     ,admin_name
                                     ,admin_lastname 
                                     ,admin_phone
                                     ,admin_date_regis
                                     ,admin_status_id                                  
                                                                         
                                     from tbl_log_in 
                                      WHERE admin_id = "+i+"";
            SqlConnection sqlconn = new SqlConnection("Server=202.44.52.248;Database=DB_Personal;User Id=personal;Password=1234;");
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];

        }

        protected void btBack_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                Server.Transfer("ListAdmin.aspx");
            }
            else
            {
                Response.Redirect("Default.aspx");

            } 
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["User"] != null && Session["Pass"] != null)
            {
                Server.Transfer("ListAdmin.aspx");
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }
}